//logs.js
const app = getApp()
var module=require("../../../utils/shanghai/chuxing.js");
Page({
  data: {
    companies:[],
  	language:'',
  	currentChoose:[],
    tabId: 0,
    businessScope: [],
    imageUrl:'',
    page:0,
  },
  onLoad: function() {
    var lang=app.globalData.lang;
    this.setData({
      language:lang,
      imageUrl:app.globalData.imageUrl,
      currentChoose:module[lang].choose,
      businessScope: module[lang].businessScope
    });
    this.changeCompanies(true);
  },
  detail(e){
    wx.navigateTo({
      url:'/pages/shanghai/chuxingxiangqing/index?id='+e.currentTarget.dataset.id
    });
  },
  selectedTap: function(e) {
    const index=e.currentTarget.dataset.index;
    this.setData({
      tabId: index,
      currentChoose:{
        businessScope:{id:Number(index),title:this.data.businessScope[Number(index)]}
      }, 
    });
    this.changeCompanies(true);
  },
  appendCompanies:function(){
    this.changeCompanies(false);
  },
  changeCompanies:function(isRefresh){
    var that=this;
    wx.showLoading({
      title:'正在加载...'
    });
    wx.request({
      url:app.globalData.url+'route/showList',
      method:'POST',
      data:{
        type:this.data.currentChoose.businessScope.id,
        language:this.data.language,
        page:isRefresh?0:this.data.page+1,
        },
      success: function(res) {
        if(res.data.code==1){
          if(isRefresh){
            var companies=res.data.data.companies;
            var page=0;
          }else{
            var companies=that.data.companies;
            var page=that.data.page+1;
            for(var i=0;i<res.data.data.companies.length;i++){
            companies.push(res.data.data.companies[i]);
            }
          }
          that.setData({
            companies:companies,
            page:page,
          },function(){
            wx.hideLoading();
          });
        }else if(res.data.code==0){
          wx.showToast({
            title:res.data.msg,
            icon:"none"
          });
        }
      } 
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: app.globalData.shareTitle,
      path: app.globalData.sharePath,
      imageUrl: '../../../images/share_img.png',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
})